﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WordWonderGame.UI.Man4
{
    public partial class FormTraLoi : UserControl
    {
        public List<int> dapAnDay;
        FormDapAn dapAnTempt;
        int soCauDung;
        public event EventHandler TraLoiDung;
        public event EventHandler DungHetRoi;
        public FormTraLoi()
        {
            InitializeComponent();
        }

        public void LoadCauHoi(Dictionary<int, string> listDapAn)
        {
            dapAnDay = new List<int>();
            for (int i = 1; i <= 8; i++)
            {
                dapAnDay.Add(i);
                dapAnDay.Add(0-i);
            }
            dapAnDay = dapAnDay.OrderBy(x => Guid.NewGuid()).ToList();
            formDapAn1.Tu = listDapAn[dapAnDay[0]];
            formDapAn1.Code = dapAnDay[0];
            formDapAn2.Tu = listDapAn[dapAnDay[1]];
            formDapAn2.Code = dapAnDay[1];
            formDapAn3.Tu = listDapAn[dapAnDay[2]];
            formDapAn3.Code = dapAnDay[2];
            formDapAn4.Tu = listDapAn[dapAnDay[3]];
            formDapAn4.Code = dapAnDay[3];
            formDapAn5.Tu = listDapAn[dapAnDay[4]];
            formDapAn5.Code = dapAnDay[4];
            formDapAn6.Tu = listDapAn[dapAnDay[5]];
            formDapAn6.Code = dapAnDay[5];
            formDapAn7.Tu = listDapAn[dapAnDay[6]];
            formDapAn7.Code = dapAnDay[6];
            formDapAn8.Tu = listDapAn[dapAnDay[7]];
            formDapAn8.Code = dapAnDay[7];
            formDapAn9.Tu = listDapAn[dapAnDay[8]];
            formDapAn9.Code = dapAnDay[8];
            formDapAn10.Tu = listDapAn[dapAnDay[9]];
            formDapAn10.Code = dapAnDay[9];
            formDapAn11.Tu = listDapAn[dapAnDay[10]];
            formDapAn11.Code = dapAnDay[10];
            formDapAn12.Tu = listDapAn[dapAnDay[11]];
            formDapAn12.Code = dapAnDay[11];
            formDapAn13.Tu = listDapAn[dapAnDay[12]];
            formDapAn13.Code = dapAnDay[12];
            formDapAn14.Tu = listDapAn[dapAnDay[13]];
            formDapAn14.Code = dapAnDay[13];
            formDapAn15.Tu = listDapAn[dapAnDay[14]];
            formDapAn15.Code = dapAnDay[14];
            formDapAn16.Tu = listDapAn[dapAnDay[15]];
            formDapAn16.Code = dapAnDay[15];
            
        }

        private void KichVaoDapAn(object sender, EventArgs e)
        {
            if (dapAnTempt == null)
            {
                dapAnTempt = (FormDapAn)sender;
                dapAnTempt.ChuyenMauBlue();
            }
            else
            {
                if (dapAnTempt.Code + ((FormDapAn)sender).Code == 0)
                {
                    //tra loi dung cau nay
                    if (TraLoiDung != null)
                    {
                        TraLoiDung(this, null);
                    }
                    soCauDung++;
                    if (soCauDung == 8)
                    {
                        if (DungHetRoi != null)
                        {
                            DungHetRoi(this, null);
                        }
                    }
                    dapAnTempt.ChuyenMauXam();
                    ((FormDapAn)sender).ChuyenMauXam();
                }
                else
                {
                    //tra loi sai cau nay
                    dapAnTempt.ChuyenMauXanh();
                }
                dapAnTempt = null;
            }
        }
    }
}
